package com.mty.mydemo.act.home;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ExpandableListView;
import com.mty.mydemo.R;
import com.mty.mydemo.act.BaseActivity;
import com.mty.mydemo.adapter.ExpandableAdapter;
import com.mty.mydemo.service.MusicService;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class HomeActivity extends BaseActivity {

    //public String SERVERADDR = "http://textile.chinatoplady.cn"; // 服务器地址

    ExpandableListView expandableListView;
    //存放数据
    private  List<String> groupArray;
    private  List<List<String>> childArray;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        startService(new Intent(this, MusicService.class));
        app.onHomeActCreate(activity);
        expandableListView= (ExpandableListView) findViewById(R.id.expand_lv);
        expandableListView.setGroupIndicator(null);
        groupArray = new ArrayList<>();
        childArray = new  ArrayList<>();
        groupArray.add("第一行" );
        groupArray.add("第二行" );
        groupArray.add("第三行" );
        groupArray.add("第四行" );
        groupArray.add("第五行" );
        final List<String> tempArray = new  ArrayList<>();
        tempArray.add("第一条" );
        tempArray.add("第二条" );
        tempArray.add("第三条" );
        for (int  index = 0 ; index <groupArray.size(); ++index)
        {
            childArray.add(tempArray);
        }
        expandableListView.setAdapter(new ExpandableAdapter(activity,groupArray,childArray));
        expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
                Log.e(TAG, "groupPosition:" + groupPosition);
                return false;//返回ture不展开，返回false展开
            }
        });
        expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
                                        long id) {
                Log.e(TAG,"groupPosition:"+groupPosition+"childPosition:"+childPosition);
                return true;
            }
        });
        expandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
            @Override
            public void onGroupExpand(int groupPosition) {
                for (int i = 0, count = expandableListView
                        .getExpandableListAdapter().getGroupCount(); i < count; i++) {
                    if (groupPosition != i) {// 关闭其他分组
                        expandableListView.collapseGroup(i);
                    }
                }
            }
        });
    }

    List<Map<String, Object>> list;


}
